(function(){
	 'use strict';
	     /**
     * @ngdoc function
     * @name webApp.controller:productcatCtr
     * @description
     * # productcatCtr
     * Controller of the webApp
     */
	 angular.module('webApp').controller('ProductcatCtrl',ProductcatCtrl);

	 ProductcatCtrl.$inject = ['$scope', 'dataService','$location','$state','helper'];

	 function ProductcatCtrl($scope,dataService,$location,$state,helper){
	 	$scope.listAction=function(){
	 		$scope.pageSize=10;
	 		$scope.getProductcatList(1);
	 	}
	 	$scope.getProductcatList=function(pageNo){
	 		var query={page_no:pageNo,page_size:$scope.pageSize};
	 		if($scope.id){
	 			query.query={id:$scope.id};
	 		}
	 		if($scope.name){
	 			query.query={name:$scope.name}
	 		}
	 		dataService.productcatGet(query).then(function(result){
	 			$scope.productcats=result.shop;
	 			$scope.productcatsTotal = result.total_count;
	 			console.log(result);
	 		});
	 	}
	 	$scope.infoAction=function(){
	 		var id=$location.search().id;
	 		dataService.productcatOne(id).then(function(result){
	 				if(result.Msg){
	 					helper.myAlert("error:"+result.error);
	 				}else{
	 					$scope.productcat=result;
	 				}
	 			});
	 	}
	 	$scope.addAction=function(){
	 		var id=$location.search().id;
	 		if(id){
	 			dataService.productcatOne(id).then(function(result){
	 				if(result.Msg){
	 					helper.myAlert("error:"+result.error);
	 				}else{
	 					$scope.productcat=result;
	 				}
	 			});
	 		}else{
	 			$scope.productcat={};
	 			$scope.productcat.name="耐克鞋子";
	 			$scope.productcat.product_num=100;
				$scope.productcat.ordinary=9;
				$scope.productcat.bronze=8;
				$scope.productcat.silver=7.5;
				$scope.productcat.gold=7;
				$scope.productcat.platinum=6.8;
	 		}
	 	}
	 	$scope.productcatDelte=function(id){
	 		dataService.productcatDelete(id).then(function(r){
	 			if(r.Msg){
	 					helper.myAlert("error:"+r.Msg)
	 				}else{
	 					helper.myAlert("success",null,null,function(){
	 						$scope.listAction();
	 					})
	 				}
	 		})
	 	}
	 	$scope.productcatAdd=function(){
	 		if($scope.productcat.id){
	 			dataService.productcatUpdate($scope.productcat).then(function(r){
	 				if(r.Msg){
	 					helper.myAlert("error:"+r.Msg);
	 				}else{
	 					helper.myAlert("success",null,null,function(){
	 						$state.go("productcat.list");
	 					});
	 				}
	 			});
	 		}else{
	 			dataService.productcatAdd($scope.productcat).then(function(r){
	 				if(r.Msg){
	 					helper.myAlert("error:"+r.Msg)
	 				}else{
	 					helper.myAlert("success",null,null,function(){
	 						$state.go("productcat.list");
	 					})
	 				}
	 			});
	 		}
	 	}
	 }
})();